package com.ppc.controller.employer;


import com.ppc.dto.UserGetMessageDTO;
import com.ppc.dto.UserSendMessageDTO;
import com.ppc.result.PageResult;
import com.ppc.result.Result;
import com.ppc.service.ChatService;
import com.ppc.vo.MessageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 雇主聊天接口
 *
 * @author jianKangS1
 * @date 2023/12/20
 */
@RestController
@RequestMapping("/employer/chat")
@Slf4j
@Api(tags = "雇主聊天接口")
public class EmployerChatController {

  @Autowired
  ChatService chatService;

  /**
   * 雇主已读消息
   *
   * @param conversationId
   * @return {@link Result }
   * @description
   */
  @PostMapping("/read")
  @ApiOperation("雇主已读消息")
  public Result readMessage(Long conversationId) {
    chatService.readMessageEmployer(conversationId);
    return Result.success();
  }


  /**
   * 雇主发送消息
   *
   * @param userSendMessageDTO
   * @return {@link Result }
   * @description
   */
  @PostMapping("/send_message")
  @ApiOperation("雇主发送消息")
  public Result sendMessage(@RequestBody UserSendMessageDTO userSendMessageDTO) {
    chatService.sendMessageEmployer(userSendMessageDTO);
    return Result.success();
  }

  /**
   * 与工人沟通
   *
   * @param workerId
   * @return {@link Result }<{@link Long }>
   * @description
   */
  @PostMapping("/add_chat")
  @ApiOperation("与工人沟通")
  public Result<Long> chatWithWorker(@RequestParam("workerId") Long workerId) {
    Long conversationId = chatService.addChatEmployer(workerId);
    return Result.success(conversationId);
  }


  /**
   * 获取聊天列表,分页查询
   *
   * @param page
   * @param pageSize
   * @return {@link Result }<{@link PageResult }>
   * @description
   */
  @GetMapping("/converstaion")
  @ApiOperation("获取聊天列表,分页查询")
  public Result<PageResult> getConverstaions(Integer page, Integer pageSize) {
    PageResult pageResult = chatService.pageQueryEmployer(page, pageSize);
    return Result.success(pageResult);

  }

  /**
   * 对话的具体消息
   *
   * @param userGetMessageDTO
   * @return {@link Result }<{@link List }<{@link MessageVO }>>
   * @description
   */
  @GetMapping("/get_message")
  @ApiOperation("对话的具体消息")
  public Result<List<MessageVO>> getMessage(UserGetMessageDTO userGetMessageDTO) {
    List<MessageVO> messageVOList = chatService.getMessage(userGetMessageDTO);
    return Result.success(messageVOList);
  }
}
